package com.longge;

import java.util.ArrayList;
import java.util.List;

public class SummaryRanges {
    public List<String> summaryRanges(int[] nums) {
        ArrayList<String> res = new ArrayList<>();
        if (nums.length == 0) return res;
        String subRes = String.valueOf(nums[0]);
        for (int i = 1; i < nums.length; i++) {
            if (nums[i - 1] != nums[i] - 1) {
                if (Integer.parseInt(subRes) != nums[i - 1]) {
                    subRes = subRes + "->" + nums[i - 1];
                }
                res.add(subRes);
                subRes = String.valueOf(nums[i]);
            }
        }
        if (Integer.parseInt(subRes) != nums[nums.length - 1]) {
            subRes = subRes + "->" + nums[nums.length - 1];
        }
        res.add(subRes);
        return res;
    }
}
